Skip to content

Conversation

sandhose
Copy link
Member

This completely overhauls how we log things.

First, it introduces a new task-level LogContext, which records task-level metrics, as well as a unique task ID.
This context is then logged when present, making it easier to correlate logs with the task that generated them.

For now, the log context only records the number of polls, the overall task duration and the CPU time used, but we could add more metrics in the future. I'm just trying to keep this PR "small".

Then, there is a new custom event formatter, which includes this log context, but also customizes how log looks in general.
Importantly, it doesn't include context from the spans anymore. This cleans up the log a lot, but may mean we're missing some context in some cases. I've done my best to restore said context, but it's not perfect.

One goal was to remove any #[instrument(err)] annotations. Two main reasons for this:

  • not all errors are 'critical', some of them need to be recorded as warnings. We have a lot of noise in Sentry because of this
  • #[instrument(err)] logs the error description and that's it. We loose a lot of information from the error stack

This is mostly replaced by a record_error! macro, which also decides whether the error is a warning or not.

For now, I've kept some #[instrument(err)] annotations in the mas-matrix-synapse and mas-storage-pg crates, as they are almost always 'internal'/bad errors that we want to log, and this PR is already massive.

Last but not least, we finally have a log entry for every single HTTP request 🎉

Fixes #2238

This can be reviewed commit by commit, even though some things are not exactly in the right order.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Apr 17, 2025

Deploying matrix-authentication-service-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: b9ae522
Status: ✅  Deploy successful!
Preview URL: https://0ce1c82d.matrix-authentication-service-docs.pages.dev
Branch Preview URL: https://quenting-better-logging.matrix-authentication-service-docs.pages.dev

View logs

@sandhose sandhose requested a review from reivilibre April 17, 2025 15:46
sandhose added 21 commits April 18, 2025 09:58
This means we can log stats about the job when it finishes, and its
status will have the right log context attached to it.
@sandhose sandhose force-pushed the quenting/better-logging branch from 75705b9 to 76adf18 Compare April 18, 2025 08:00
Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exciting! Looks very plausible, if there's anything minor that needs improvement I'm sure this can happen in a subsequent PR

@sandhose sandhose changed the title New logging New logging output Apr 23, 2025
@sandhose sandhose added the T-Enhancement New feature of request label Apr 23, 2025
@sandhose sandhose enabled auto-merge April 23, 2025 16:37
@sandhose sandhose merged commit 7e715fb into main Apr 23, 2025
21 checks passed
@sandhose sandhose deleted the quenting/better-logging branch April 23, 2025 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-Enhancement New feature of request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: logging REST calls

2 participants